home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / windows / 4nt300.zip / EXAMPLES.BTM (.txt) < prev    next >
Microsoft Windows Help File Content  |  1997-07-30  |  13KB  |  298 lines

  1. :: examples.btm
  2. :: 24-jul-97
  3. :: Copyright 1997, JP Software Inc., All Rights Reserved.
  4. :: Published by JP Software Inc., P.O. Box 1470, E. Arlington, MA 02174,
  5. :: USA, or http://www.jpsoft.com/
  6. :: This sample batch file is distributed with 4DOS, 4OS2, 4NT, and Take
  7. :: Command.  To see how it works simply run EXAMPLES from your command
  8. :: processor's prompt.
  9. :: You are free to extract items from this batch file for your own use with
  10. :: our products.  However, this file can not be modified and then
  11. :: redistributed; it is distributed only by JP Software Inc.
  12. *@echo off
  13. *setlocal
  14. *unalias *
  15. *unset *
  16. on break goto done
  17. on error rem
  18. window max
  19. do forever
  20.   cls
  21.   echos Executing: %_batchname under
  22.   ver /r
  23.   text
  24.   This batch file contains a few basic examples of how the
  25.   various variable functions can be used in your own code.
  26.   Please press a number [0-8] corresponding to one of the categories
  27.   below to see some sample output, or any other key to exit.
  28.       0. LIST this batch file
  29.       1. System status
  30.       2. Drives and devices
  31.       3. Files
  32.       4. File names
  33.       5. Strings and characters
  34.       6. Numbers and arithmetic
  35.       7. Dates and times
  36.       8. Utility
  37.   endtext
  38.   inkey /c /p /w60 /x Which? %%s
  39.   cls
  40.   iff islabel _%s then
  41.     gosub _%s
  42.     echo ``
  43.     echo ``
  44.     iff "%s" ne "0" then
  45.       echos   Press "L" to LIST this section,
  46.       echos  any other key to return to the menu
  47.       inkey /c /p /x %%i
  48.       if "%i" eq "L" list /t":_%s" %_batchname
  49.     endiff
  50.   else
  51.     leave
  52.   endiff
  53. enddo
  54. :done
  55. window rest
  56. list %_batchname
  57. return
  58. echo    1.FUNCTIONS: System status
  59. echo ``
  60. setdos /x-5
  61. echo %%@DOSMEM[[b|k|K|m|M]c]    Free DOS memory:       %@dosmem[bc] bytes
  62. echo %%@EMS[[b|k|K|m|M]c]       Free EMS memory:       %@ems[bc] bytes
  63. echo %%@XMS[[b|k|K|m|M]c]       Free XMS memory:       %@xms[bc] bytes
  64. echo %%@EXTENDED[[b|k|K|m|M]c]  Free extended memory:  %@extended[bc] bytes
  65. setdos /x5
  66. echo ``
  67. set jp=foo
  68. set /m jp=bar
  69. if "%@master[jp]" ne "" echos %%@MASTER[varname]
  70. iff "%@master[jp]" eq "%jp" then
  71.    echo          String "%%JP" expands to "%@master[jp]" in a single master/local environment.
  72.    echo          String "%%JP" expands to "%jp" locally (shell #%_shell), but to "%@master[jp]" in the master environment.
  73. endiff
  74. unset /m jp
  75. echo ``
  76. echo %%@READSCR[row,col,len]    The six characters starting with the ninth
  77. echo                           column of the top row of the screen are
  78. echo                           "%@readscr[0,8,6]"
  79. return
  80. echo    2.FUNCTIONS: Drives and devices
  81. echo ``
  82. set i=%_disk
  83. echo  (using current drive "%i:")
  84. echo ``
  85. echo %%@DISKTOTAL[d:,M]     Total disk space: %@format[12,%@disktotal[%i,M]] MB
  86. echo %%@DISKUSED[d:,K]      Used disk space:  %@format[12,%@diskused[%i,K]] KB
  87. echo %%@DISKFREE[d:,b]      Free disk space:  %@format[12,%@diskfree[%i,b]] bytes
  88. echo %%@LABEL[d:]           Volume label:     %@format[13,"%@label[%i]"]
  89. echo %%@CDROM[d:]           Drive is %@if[%@cdrom[%i] eq 0,NOT ,]a CD-ROM
  90. echo %%@READY[d:]           Drive is %@if[%@ready[%i] eq 0,NOT ,]ready
  91. echo %%@REMOTE[d:]          Drive is %@if[%@remote[%i] eq 0,NOT ,]remote
  92. echo %%@REMOVABLE[d:]       Drive is %@if[%@removable[%i] eq 0,NOT ,]removable
  93. echo %%@FSTYPE[d:]          The file system is %@FSTYPE[%i]
  94. echo ``
  95. echo %%@DEVICE[name]
  96. for %i in (NUL: CON: COM1: COM5: CLIP:) (
  97.   echo                       Device %i %@if[%@device[%i] eq 0,NOT ,]found
  98. echo %%@LPT[n]              Printer port LPT2 is %@if[%@lpt[2] eq 0,NOT ,]ready
  99. return
  100. echo    3.FUNCTIONS: Files %@if[%_rows lt 26,(screen 1),]
  101. echo ``
  102. set i=%_batchname
  103. echo  (using this batch file as "filename")
  104. echo ``
  105. if x%@descript[%i] eq x describe "%i" "Batch language examples"
  106. echo %%@DESCRIPT[filename]             %@descript[%i]
  107. echo %%@TRUENAME[filename]             %@truename["%i"]
  108. echo %%@ALTNAME[filename]              %@altname["%i"]
  109. echos %%@ATTRIB[filename,[nrhsda]]      File is %@if[%@attrib["%i",r,p] eq 0,NOT ,]readonly
  110. echo  (%@attrib["%i"])
  111. echo %%@FILEAGE[filename]              %@fileage["%i"]
  112. echo %%@FILEDATE[filename]             %@filedate["%i"]
  113. echo %%@FILETIME[filename]             %@filetime["%i"]
  114. echo %%@LINES[filename]                This file contains %@lines["%i"] lines
  115. echo %%@LINE[filename,n]               Its sixth line is "%@line["%i",5]"
  116. echo                                  and its last line is "%@line["%i",%@lines["%i"]]"
  117. echo ``
  118. echos %%@FILEOPEN[filename,mode]
  119. set jp=%@fileopen[%i,read,b]
  120. echo         Open file for READ in BINARY mode as handle #%jp
  121. echos %%@FILESEEK[n,offset,start]       Move pointer 8 bytes from beginning
  122. echo  (result=%@fileseek[%jp,8,0])
  123. echos                                  Move another 10 bytes
  124. echo  (result=%@fileseek[%jp,10,1])
  125. echo %%@FILEREAD[n [,length]]          Read next 5 bytes: "%@fileread[%jp,5]"
  126. echo %%@FILECLOSE[n]                   Close handle #%jp: result=%@fileclose[%jp]
  127. echo ``
  128. if %_rows lt 26 (
  129.   pause Presss any key for more ...
  130.   cls
  131.   echo    3.FUNCTIONS: Files (screen 2)
  132.   echo ``
  133. set i=*.txt
  134. set j=%@filesize[%i,b]
  135. if %j eq -1 set j=0
  136. echo %%@FILESIZE[%i,b]              "%i" files occupy %j bytes
  137. echo %%FILES[%i]                    with %@files[%i] matching file(s)
  138. echo                                  in this "%_cwd\" directory.
  139. echo ``
  140. set i=\*
  141. echo %%@FINDFIRST[filename[,-nrhsda]]  First directory in the root: "%@findfirst[%i,d]"
  142. echo %%@FINDNEXT[filename[,-nrhsda]]   Next directory in the root: "%@findnext[%i,d]"
  143. echo                                  Next directory in the root: "%@findnext[%i,d]"
  144. echo                                  etc.
  145. echo %%@FINDCLOSE[filename]            Close search handle for "%i" (result=%@findclose[%i])
  146. echo ``
  147. set i=%@unique[.]
  148. echo %%@UNIQUE[d:\path]                Create file with unique name: %@filename["%i"]
  149. *del %i
  150. return
  151. echo    4.FUNCTIONS: File names
  152. echo ``
  153. set i=%_batchname
  154. echo  (using this batch file as "filename")
  155. echo ``
  156. echo %%@EXT[filename]       Extension only:      %@ext["%i"]
  157. echo %%@FULL[filename]      Name with path:      %@full["%i"]
  158. echo %%@FILENAME[filename]  Name and extension:  %@filename["%i"]
  159. echo %%@NAME[filename]      Name only:           %@name["%i"]
  160. echo %%@PATH[filename]      Path only:           %@path["%i"]
  161. echo %%@LFN[filename]       Long Name:           %@lfn[%i]
  162. echo %%@SFN[filename]       Short Name:          %@sfn[%i]
  163. echo ``
  164. echo %%@EXPAND[filename,[nrhsda]]     The *.TXT files in this directory are:
  165. echo    %@EXPAND[*.txt,-d]
  166. return
  167. echo    5.FUNCTIONS: Strings and characters %@if[%_rows lt 26,(screen 1),]
  168. echo ``
  169. set i=%_dow
  170. echo %%@ASCII[c]                      Numeric ASCII value: "%i" is:
  171. echos                                 ASCII %@ascii[%@instr[0,1,%i]] +
  172. echos  ASCII %@ascii[%@instr[1,1,%i]] +
  173. echo  ASCII %@ascii[%@instr[2,1,%i]]
  174. echos %%@SUBSTR[string,start,length]   The middle character of "%i" is
  175. echo  "%@substr[%i,1,1]"
  176. echos %%@REPEAT[c,n]                   Repeat a character:
  177. echo       %@repeat[-,3] %@repeat[ ,5]-
  178. set i=   %i %_day`   `
  179. echo %%@TRIM[string]                  Remove blanks from "%i": "%@trim[%i]"
  180. set i=Windows
  181. echo %%@INSERT[n,string1,string2]     "%i" becomes "%@insert[4,s of sorr,%i]"
  182. set i=%@random[65,90]
  183. echo %%@CHAR[n]                       ASCII %i is character "%@char[%i]"
  184. echo %%@FORMAT[[-][x][.y],string]     `|`                  `|`
  185. echo               adjust right:     %@format[20,%_date]
  186. echo                                 %@format[20,%@eval[355/113]]
  187. echo                                 %@format[20.5,%@eval[355/113]]
  188. echo                adjust left:     %@format[-20,%_date]
  189. echo                                 %@format[-20,%@eval[355/113]]
  190. echo                                 %@format[-20.5,%@eval[355/113]]
  191. set i=*o[sw]*
  192. echos %%@WILD[str1,str2]               Wildcard "%i" DOES
  193. echo  %@if[%@WILD[%_cwd,%i] eq 0,NOT ,]appear in
  194. echo                                 "%_cwd".
  195. echo ``
  196. if %_rows lt 26 (
  197.   pause Presss any key for more ...
  198.   cls
  199.   echo    5.FUNCTIONS: Strings and characters (screen 2)
  200.   echo ``
  201. set i=The bug which you would fright me with, I seek.
  202. echo  (using string "%i",
  203. echo   from William Shakespeare, The Winter's Tale, III,2)
  204. echo ``
  205. echo %%@LEN[string]                 The test string contains %@len[%i] characters.
  206. echo %%@LOWER[string]               "%@lower[%i]"
  207. echo %%@UPPER[string]               "%@upper[%i]"
  208. echo %%@WORDS[["sep",]string]       Number of words: %@words[%i]
  209. echo %%@WORD[["sep",]n,string]      Third word: "%@word[2,%i]"
  210. echos %%@INDEX[string1,string2]      The first "u" is character #
  211. echo %@index["%i",u]
  212. echos %%@INSTR[start,length,string]  The "f" is followed by:
  213. echo  "%@INSTR[%@index["%i",f],15,%i]..."
  214. echo %%@LEFT[n,string]              The leftmost 7 characters are "%@left[7,%i]"
  215. echo %%@RIGHT[n,string]             The rightmost 7 characters are "%@right[7,%i]"
  216. echo %%@REPLACE[str1,str2,str3]     "%@replace[ which you would,s you,%i]"
  217. echo %%@STRIP[chars,string]         No vowels: "%@strip[aeiuo,%i]"
  218. return
  219. echo    6.FUNCTIONS: Numbers and arithmetic
  220. echo ``
  221. set i=%@eval[1234567890 / 100000]
  222. echo  (using an arbitrary number of %i)
  223. echo %%@COMMA[n]          Inserts thousands separators in a number: %@comma[%i]
  224. echo %%@DEC[%%var]         Decremented value of a variable: %@dec[%i]
  225. echo %%@INC[%%var]         Incremented value of a variable: %@inc[%i]
  226. echo ``
  227. echo %%@EVAL[expression]  Arithmetic calculations: 355 / 113 = %@eval[355 / 113=.5] (rounded)
  228. set n=%i
  229. echos %%@INT[n]            Integer part of a number - enter a number:
  230. input /c /x /e /l10 /w30 `` %%n
  231. screen %_row, %@eval[%_column - %@len[%n] - 27]
  232. iff %@numeric[%n] eq 0 then
  233.   beep
  234.   set n=%i
  235. endiff
  236. echo number %n is %@int[%n] `              `
  237. set i=%_4ver
  238. echos %%@NUMERIC[string]   Test if a string is numeric - enter string:
  239. input /c /x /e /l10 /w30 `` %%i
  240. screen %_row, %@eval[%_column - %@len[%i] - 36]
  241. echo string "%i" is numeric: %@numeric[%i] (0=No, 1=Yes)
  242. echos %%@RANDOM[min,max]   Generate a random integer:
  243. do 8 times
  244.   echos  %@random[0,7],
  245. enddo
  246. echo  etc.
  247. echo %%@CONVERT[in,out,value]       Base conversion:
  248. echo                                  decimal (10): %n
  249. echo                                  hexadecimal (16): %@convert[10,16,%n]
  250. echo                                  octal (8): %@convert[10,8,%n]
  251. echo                                  binary (2): %@convert[10,2,%n]
  252. return
  253. echo    7.FUNCTIONS: Dates and times
  254. echo ``
  255. echo  (using the current system date of %_date and time of %_time)
  256. echo %%@DATE[mm-dd-yy]          Convert date to number of days: %@date[%_date]
  257. echo %%@MAKEAGE[date[,time]]    Convert date/time to file date/time: %@makeage[%_date[,%_time]]
  258. echo %%@TIME[hh:mm:ss]          Convert time to number of seconds: %@time[%_time]
  259. echo %%@DAY[mm-dd-yy]           Day of the month: %@day[%_date]
  260. echo %%@DOW[mm-dd-yy]           Day of the week: %@dow[%_date]
  261. echo %%@DOWI[mm-dd-yy]          Numeric day of the week: %@dowi[%_date]
  262. echo %%@DOY[mm-dd-yy]           Numeric day of the year: %@doy[%_date]
  263. echo %%@MONTH[mm-dd-yy]         Month of the year: %@month[%_date]
  264. echo %%@YEAR[mm-dd-yy]          Year number (2 digits): %@year[%_date]
  265. echo ``
  266. echo  (using an arbitrary number of 1234 days)
  267. echo %%@MAKEDATE[n]           Convert number of days to date: %@makedate[1234]
  268. echo ``
  269. echo  (using an arbitrary number of 1234 seconds)
  270. echo %%@MAKETIME[n]           Convert number of seconds to time: %@maketime[1234]
  271. echo ``
  272. echo  (combining date/time functions)
  273. echo In thirty minutes, the time will be %@maketime[%@eval[%@time[%_time]+1800]]
  274. echo In one week, the date will be %@makedate[%@eval[%@date[%_date]+7]]
  275. return
  276. echo    8.FUNCTIONS: Utility
  277. timer on /3 > nul
  278. echo ``
  279. echo  (using a temporary alias for FORMAT)
  280. alias format=`beep%+echo Too dangerous! `
  281. echo %%@ALIAS[name]    Value of an alias: FORMAT is "%@alias[format]"
  282. unalias format
  283. echo ``
  284. echos %%@IF[condition,true,false]   Evaluates a test condition:
  285. echo  Good %@if[%_hour lt 12,morning,afternoon]!
  286. echo ``
  287. echo  (using this file as input - select a line from the box below)
  288. set i=%_batchname
  289. echos %%@SELECT[file,t,l,b,r,title]  Menu selection:
  290. echo  You selected "%@word[0,%@select[%i,12,2,17,25, This is a test ]]..."
  291. echo ``
  292. echo  (a TIMER was started when you displayed this page)
  293. echo %%@TIMER[n]                    Elapsed time of specified timer: %@timer[3]
  294. echo %%@CLIP[n]                     The first line of your Windows clipboard is:
  295. echo "%@clip[0]"
  296. return
  297. :: examples.btm
  298.